﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using MallInteractiveMap.Common;

namespace MallInteractiveMap.CMSWebClient.Common
{
    public class BasePage : Page
    {
        protected void RegisterStartupScript(string script)
        {
            System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "StartupScript", script, true);
        }

        protected void ShowMessage(string msg, string title)
        {
            //string strScript = "jAlert('" + msg + "' , '" + title + "' );";
            string strScript = string.Format("alert('{0}' , '{1}' );", msg, title);
            System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "keyMessageBox", strScript, true);
        }

        protected string GetFileName(string fileName)
        {
            if (fileName.LastIndexOf('\\') > -1)
            {
                return fileName.Substring(fileName.LastIndexOf('\\') + 1, fileName.Length - fileName.LastIndexOf('\\') - 1);
            }
            else
            {
                return fileName;
            }
        }

        
    }
    public class DetailBasePage<T>:BasePage
    {
        protected List<T> ViewData { get; set; }

        protected List<T> SortViewData(string expression)
        {
            if (this.ViewData.Count > 0)
            {
                this.ViewData = this.ViewData.Sort<T>(expression, this.GridSortDirection).ToList<T>().ToList<T>();
            }
            return this.ViewData;
        }
        /// <summary>
        /// returns sort direction. 
        /// </summary>
        protected string GridSortDirection
        {
            get
            {
                if (ViewState["SortDirection"] == null)
                {
                    ViewState["SortDirection"] = "DESC";
                }
                string sortDir = Convert.ToString(ViewState["SortDirection"]);
                if (sortDir.Equals("ASC"))
                {
                    ViewState["SortDirection"] = "DESC";
                }
                else
                {
                    ViewState["SortDirection"] = "ASC";
                }
                return sortDir;
            }
        }
    }
}